<link rel="stylesheet" href="__STATIC__/css/pccomment.css"> 
<div class="WapCommentBox">
	<ul class="PostCommentBox1">
		<ol><i class="fa fa-edit"></i><textarea placeholder="发布您的精彩评论"></textarea></ol>
		<li><button type="butter" onclick="post_commentPc()">发表</button></li>		
	</ul>
	<div class="head">
		<div class="tag">全部评论</div>
	</div>
	<div class="ListComment">
		<?php if(is_array($listdb) || $listdb instanceof \think\Collection || $listdb instanceof \think\Paginator): $i = 0; $__LIST__ = $listdb;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$rs): $mod = ($i % 2 );++$i;?>
		<ul class="lists" id="comment_cnt_<?php echo $rs['id']; ?>">
			<ol class="icon"><a href="<?php echo get_url('user',$rs['uid']); ?>" target="_blank"><img src="<?php echo $rs['icon']; ?>" onerror="this.src='__STATIC__/images/nobody.gif'"/></a></ol>
			<li class="infos">
				<dl>
					<dt><a href="<?php echo murl('member/msg/add',['uid'=>$rs['uid']]);?>" class="_pop"><?php echo $rs['username']; ?></a> <span><?php echo $rs['time']; ?></span></dt>
					<dd>
						<em onclick="dingcomment(<?php echo $rs['id']; ?>)"><i class="si si-like"></i> <a class="agree<?php echo $rs['id']; ?>"><?php echo $rs['agree']; ?></a></em> 
						<span onclick="post_comment(<?php echo $rs['id']; ?>)"><i class="fa fa-commenting-o"></i> 回复</span>
						<?php if($rs['uid']==login_user('uid')||login_user('groupid')==3): ?><span onclick="del_comment(<?php echo $rs['id']; ?>)"><a href="javascript:"><i class="fa fa-close"></i> 删除</a></span><?php endif; ?>
					</dd>
				</dl>
				<div class="comment"><?php echo $rs['content']; ?></div>				
				<div class="repalyinfs repalyinfs<?php echo $rs['id']; ?>">
					<?php if(is_array($rs['children']) || $rs['children'] instanceof \think\Collection || $rs['children'] instanceof \think\Paginator): $i = 0; $__LIST__ = $rs['children'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
						<div id="comment_cnt_<?php echo $vo['id']; ?>">
						<a href="<?php echo get_url('user',$vo['uid']); ?>" target="_blank"><?php echo (isset($vo['username']) && ($vo['username'] !== '')?$vo['username']:'游客'); ?>：</a>
						<?php echo $vo['content']; ?>
						<?php if($vo['uid']==login_user('uid')||login_user('groupid')==3): ?><span onclick="del_comment(<?php echo $vo['id']; ?>)" style="float:right;"><a href="javascript:"><i class="fa fa-close"></i> 删除</a></span><?php endif; ?>
					</div>
					<?php endforeach; endif; else: echo "" ;endif; ?>
				</div>
			</li>
		</ul>
		<?php endforeach; endif; else: echo "" ;endif; ?>
	</div>
	<div class="ShowMoreComment"><button type="butter" onclick="ShowMoreComment()">更多评论 <i class="fa fa-angle-double-down"></i></button></div>
</div>
<script type="text/javascript">
	var posturl,baseurl;
		posturl=baseurl="<?php echo fun('label@comment_api','posturl',$aid,$sysid,$cfg_array); ?>";
	var repalyid=0;
	var commentpage=1;
	function post_comment(pid){			
		if(pid>0){
			repalyid=pid;
			posturl=baseurl+"?pid="+pid;
		}
		layer.open({
		  type: 1,
		  skin: 'layui-layer-demo', //样式类名
		  area: ['320px', '280px'], //宽高
		  closeBtn: 0, //不显示关闭按钮
		  anim: 2,
		  shadeClose: true, //开启遮罩关闭
		  content: '<ul class="PostCommentBox"><ol><textarea placeholder="请输入评论内容"></textarea></ol><li><button type="butter" onclick="post_comment1()">发表</button><button type="butter" onclick="layer.closeAll()">取消</button></li></ul>'
		});
	}

function del_comment(id){
	layer.confirm('你确认要删除吗？',function(){
		$.get("<?php echo purl('comment/api/delete');?>?ids="+id,function(res){
			if(res.code==0){
				layer.msg('删除成功');
				$("#comment_cnt_"+id).hide();
			}else{
				layer.alert(res.msg);
			}
		});
	});
}
	
	//引用评论
	function post_comment1(){
		var contents=$('.PostCommentBox textarea').val();
		if(contents==''){
			layer.alert("请输入评论内容！");
		}else{
			$.post(
				posturl,
				{content:contents},
				function(res,status){
					if(res.code==0){
						if(repalyid>0){
							$('.repalyinfs'+repalyid).html(res.data);
						}else{
							$('.ListComment').html(res.data);
							commentpage=1;
							//$('.ShowMoreComment').fadeIn();
						}
						layer.closeAll(); //疯狂模式，关闭所有层
						layer.msg('发表成功！');
						HiddenShowMoreComment();
					}else{
						layer.alert('评论发表失败:'+res.msg);
					}
				}
			);				
		}			
	}
	
	
	function post_commentPc(){
		var contents=$('.PostCommentBox1 textarea').val();
		if(contents==''){
			layer.alert("请输入评论内容！");
		}else{
			$('.PostCommentBox1 textarea').val('评论发表中……');
			$('.PostCommentBox1 li').html('<span>发表中</span>');
			$.post(
				posturl,
				{content:contents},
				function(res,status){
					$('.PostCommentBox1 textarea').val('');
					$('.PostCommentBox1 li').html('<button type="butter" onclick="post_commentPc()">发表</button>');
					if(res.code==0){
						$('.ListComment').html(res.data);
						commentpage=1;
						layer.msg('发表成功！');
						HiddenShowMoreComment();
					}else{
						layer.alert('评论发表失败:'+res.msg);
					}
				}
			);				
		}
	}

	function dingcomment(id){
			var agree=parseInt($('.agree'+id).html());
			$.get('<?php echo fun("label@comment_api","posturl",$aid,$sysid,$cfg_array); ?>?agree=1&id='+id+'&'+Math.random(),function(res){
				if(res.code==0){
					agree++;
					$('.agree'+id).html(agree);
					layer.msg('点赞成功！');
				}else{
					layer.alert('点赞失败:'+res.msg);
				}
			});
	}
		
	function ShowMoreComment(){
			commentpage++;
			$.get('<?php echo fun("label@comment_api","pageurl",$aid,$sysid,$cfg_array); ?>?page='+commentpage+'&'+Math.random(),function(res){
				if(res.code==0){
					if(res.data==''){
						layer.msg('显示完了！');
						$('.ShowMoreComment').fadeOut();
					}else{
						res.data="<div class='pages"+commentpage+"'>"+res.data+"</div>";			
						$('.ListComment').append(res.data);
						$('.ListComment .pages'+commentpage).hide();
						$('.ListComment .pages'+commentpage).show(500);
					}
				}else{
					layer.msg(res.msg,{time:2500});
				}
			});
	}

	function HiddenShowMoreComment(){
			var Comments=$('.ListComment .lists').length;
			if(parseInt(Comments/<?php echo $cfg_array['rows']; ?>)<1){
				$('.ShowMoreComment').hide();
			}else{
				$('.ShowMoreComment').show();
			}
	}

	HiddenShowMoreComment();
</script>